package cn.ffcs.uec.outStaff.component;

import java.io.FileInputStream;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.util.media.Media;
import org.zkoss.web.servlet.Servlets;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zk.ui.event.UploadEvent;
import org.zkoss.zkplus.databind.BindingListModelList;
import org.zkoss.zul.Div;
import org.zkoss.zul.Filedownload;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Window;

import cn.ffcs.raptornuke.plugin.common.zk.util.ZkUtil;
import cn.ffcs.uec.common.util.PermissionUtil;
import cn.ffcs.uec.common.vo.UecBdDefdoc;
import cn.ffcs.uec.outStaff.constant.UecOutStaffConstants;
import cn.ffcs.uec.outStaff.manager.UecOutStaffManager;
import cn.ffcs.uec.outStaff.model.UecOutStaffInfo;
import cn.ffcs.uec.recordsApproval.constant.ApprovalConstants;
import cn.ffcs.uec.recordsApproval.util.ApprovalUtil;
import cn.ffcs.uec.staff.component.bean.UecAssListboxBean;
import cn.ffcs.uec.staff.manager.UecAssManager;
import cn.ffcs.uec.staff.manager.UecTrialManager;
import cn.ffcs.uec.staff.model.UecAss;
import cn.ffcs.uec.staff.model.UecTrial;
import cn.ffcs.uom.common.constants.BaseUnitConstants;
import cn.ffcs.uom.common.model.DefaultDaoFactory;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.FileUtil;
import cn.ffcs.uom.common.util.IPortletInfoProvider;
import cn.ffcs.uom.common.util.ListboxUtils;
import cn.ffcs.uom.common.util.PlatformUtil;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;
import cn.ffcs.uom.common.zul.PubUtil;
import lombok.Getter;
import lombok.Setter;

/**
 * @Title:考核信息 CRUD插件
 * @Description:
 * @Company: FFCS
 * @since JDK1.6
 */
@Controller
@Scope("prototype")
public class UecOutStaffAssListboxExt extends Div implements IdSpace {

	private static final long serialVersionUID = -5811398149406451671L;
	/**
	 * 人员基本信息功能 查询出的实体对象
	 */
	private UecOutStaffInfo uecOutStaffInfo;
	/**
	 * 对应页面上的bean
	 */
	private UecAssListboxBean bean = new UecAssListboxBean();
	/**
	 * 人员考核信息实体
	 */
	private UecAss uecAss;
	/**
	 * 人员考核翻页查询条件实体
	 */
	private UecAss assPaging;

	/**
	 * 员工考核信息list
	 */
	private List<UecAss> uecAssList = new ArrayList<UecAss>();

	/**
	 * 上传文件
	 */
	private Media media;

	private static final int TOTAL_COLUMN = 11;

	/**
	 * 
	 */
	private boolean assesmentCleanFlag = false;

	/**
	 * 人员语言能力查询实体
	 */
	// private UecAss qryUecAss;

	private UecAssManager uecAssManager = (UecAssManager) ApplicationContextUtil
			.getBean("uecAssManager");

	private UecTrialManager uecTrialManager = (UecTrialManager) ApplicationContextUtil
			.getBean("uecTrialManager");

	private UecOutStaffManager uecOutStaffManager = (UecOutStaffManager) ApplicationContextUtil
			.getBean("uecOutStaffManager");

	@Getter
	@Setter
	private IPortletInfoProvider portletInfoProvider;

	public UecOutStaffAssListboxExt() {
		Executions.createComponents(
				UecOutStaffConstants.UEC_OUT_STAFF_ASS_EXT_LISTBOX_ZUL, this,
				null);
		Components.wireVariables(this, bean);
		Components.addForwards(this, this, '$');

		this.addForward(UecOutStaffConstants.ON_UEC_OUT_STAFF_ASS_QUERY, this,
				UecOutStaffConstants.ON_UEC_OUT_STAFF_ASS_QUERY_RESPONSE);

		this.addForward(UecOutStaffConstants.ON_CLEAN_UEC_OUT_STAFF_ASS, this,
				UecOutStaffConstants.ON_CLEAN_UEC_OUT_STAFF_ASS_RESPONSE);

		this.addForward("onAssesmentQuery", this, "onAssesmentQueryResponse");
		this.addForward("onCleanAssesmentQuery", this,
				"onCleanAssesmentQueryResponse");

	}

	/**
	 * 初始化
	 */
	public void onCreate() {
		this.setButtonValid(true, true, false, false, false, false);
	}

	/**
	 * 选择查询记录
	 * 
	 * @throws Exception
	 */
	public void onSelectUecAssList() throws Exception {
		if (this.bean.getUecAssListbox().getSelectedCount() > 0) {
			uecAss = (UecAss) bean.getUecAssListbox().getSelectedItem()
					.getValue();
		}
	}

	/**
	 * 监听 UecOutStaffAssesmentMainComposer 中传过来的事件
	 * 
	 * @param event
	 */
	public void onAssesmentQueryResponse(ForwardEvent event) {
		uecOutStaffInfo = (UecOutStaffInfo) event.getOrigin().getData();
		if (null != uecOutStaffInfo) {
	        //设置操作按钮，非盟市主管不可操作按钮
	        if(PermissionUtil.isNoMainOutStaff()) {
	            this.setButtonValid(true, true, true, true,true,true);
	        }else {
	            this.setButtonValid(true, true, false, true, true, false);
	        }
			uecAss = new UecAss();
			uecAss.setStaffId(uecOutStaffInfo.getOutStaffId());
			uecAss.setNmStaffType(BaseUnitConstants.NM_OUT_STAFF_TYPE);
			assPaging = uecAss;
			this.onQueryUecAss();
		}
	}

	/**
	 * 监听 UecOutStaffAssesmentMainComposer 中传过来的事件
	 * 
	 * @param event
	 */
	public void onCleanAssesmentQueryResponse(ForwardEvent event) {
		assesmentCleanFlag = (Boolean) event.getOrigin().getData();
		if (assesmentCleanFlag) {
			clearVariable();
			uecOutStaffInfo = null;
			ListboxUtils.clearListbox(this.bean.getUecAssListbox());
			this.bean.getUecAssListboxPaging().setTotalSize(1);
			this.setButtonValid(false, false, false, false, false, false);
		}
	}

	/**
	 * 人员基本信息功能，抛出事件， 事件监听
	 * 
	 * @param event
	 */
	public void onUecOutStaffAssQueryResponse(ForwardEvent event) {
		uecOutStaffInfo = (UecOutStaffInfo) event.getOrigin().getData();
		if (null != uecOutStaffInfo) {
	        //设置操作按钮，非盟市主管不可操作按钮
            if(PermissionUtil.isNoMainOutStaff()) {
                this.setButtonValid(false, false, false, false,false,false);
            }else {
                this.setButtonValid(true, true, true, true, true, false);
            }
			uecAss = new UecAss();
			uecAss.setStaffId(uecOutStaffInfo.getOutStaffId());
			uecAss.setNmStaffType(BaseUnitConstants.NM_OUT_STAFF_TYPE);
			assPaging = uecAss;
			this.onQueryUecAss();
		}
	}

	public void onCleanUecAssResponse(ForwardEvent event) {
		clearVariable();
		uecOutStaffInfo = null;
		ListboxUtils.clearListbox(this.bean.getUecAssListbox());
		this.bean.getUecAssListboxPaging().setTotalSize(1);

		this.setButtonValid(false, false, false, false, false, false);
	}

	/**
	 * 设置按钮
	 * 
	 * @param canAdd
	 * @param candel
	 */
	private void setButtonValid(boolean canDownload, boolean canUpload,
			boolean canView, boolean canAdd, boolean canEdit, boolean candel) {
		this.bean.getDownloadButton().setDisabled(!canDownload);
		this.bean.getUploadButton().setDisabled(!canUpload);
		this.bean.getViewButton().setDisabled(!canView);
		this.bean.getAddButton().setDisabled(!canAdd);
		this.bean.getEditButton().setDisabled(!canEdit);
		this.bean.getDelButton().setDisabled(!candel);
	}

	/**
	 * 查询按钮
	 */
	public void onQueryUecAss() {
		this.bean.getUecAssListboxPaging().setActivePage(0);
		this.onQueryUecAssList();
	}

	/**
	 * 重置按钮
	 */
	public void onResetUecAss() {
		ListboxUtils.clearListbox(this.bean.getUecAssListbox());
		this.bean.getUecAssListboxPaging().setTotalSize(1);
	}

	/**
	 * 查看按钮
	 * 
	 * @throws Exception
	 * @throws InterruptedException
	 */
	public void onViewUecAss() throws Exception, InterruptedException {
		if (null != uecAss) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("opType", "view");
			map.put("uecAss", uecAss);
			map.put("uecOutStaffInfo", uecOutStaffInfo);
			Window window = (Window) Executions.createComponents(
					UecOutStaffConstants.UEC_OUT_STAFF_ASS_EDIT_ZUL, this, map);
			window.doModal();
			window.addEventListener("onOK", new EventListener() {
				@Override
				public void onEvent(Event event) throws Exception {
					if (event.getData() != null) {
						//
					}
				}
			});
		} else {
			ZkUtil.showError("请选中要查看的记录", "提示信息");
		}
	}

	/**
	 * 新增按钮
	 * 
	 * @throws Exception
	 * @throws
	 */
	public void onAddUecAss() throws Exception {
		if (null != uecOutStaffInfo) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("opType", "add");
			map.put("uecOutStaffInfo", uecOutStaffInfo);
			Window window = (Window) Executions.createComponents(
					UecOutStaffConstants.UEC_OUT_STAFF_ASS_EDIT_ZUL, this, map);
			window.doModal();
			window.addEventListener("onOK", new EventListener() {
				@Override
				public void onEvent(Event event) throws Exception {
					if (event.getData() != null) {
						// 新增或修改完成后，列表从数据库更新
						uecAss = (UecAss) event.getData();
						onQueryUecAssList();
					}
				}
			});
		}
	}

	/**
	 * 编辑按钮
	 * 
	 * @throws Exception
	 * @throws InterruptedException
	 */
	public void onEditUecAss() throws Exception, InterruptedException {
		if (null != uecAss) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("opType", "edit");
			map.put("uecAss", uecAss);
			map.put("uecOutStaffInfo", uecOutStaffInfo);
			Window window = (Window) Executions.createComponents(
					UecOutStaffConstants.UEC_OUT_STAFF_ASS_EDIT_ZUL, this, map);
			window.doModal();
			window.addEventListener("onOK", new EventListener() {
				@Override
				public void onEvent(Event event) throws Exception {
					if (event.getData() != null) {
						// 新增或修改完成后，列表从数据库更新
						uecAss = (UecAss) event.getData();
						onQueryUecAssList();
					}
				}
			});
		} else {
			ZkUtil.showError("请选择要编辑的记录", "提示信息");
			return;
		}
	}

	/**
	 * 删除按钮
	 */
	public void onDelUecAss() {
		if (uecAss != null) {
			ZkUtil.showQuestion("确定要删除吗?", "提示信息", new EventListener() {
				public void onEvent(Event event) throws Exception {
					Integer result = (Integer) event.getData();
					if (result == Messagebox.OK) {
						uecAss.removeOnly();
						PubUtil.reDisplayListbox(bean.getUecAssListbox(),
								uecAss, "del");
						uecAss = null;
					}
				}
			});
		} else {
			ZkUtil.showError("请选择要删除的记录", "提示信息");
			return;
		}
	}

	/**
	 * 下载模版
	 */
	@SuppressWarnings("deprecation")
	public void onDownloadTemplate() {
		try {
			String charset = "UTF-8";
			// 服务器文件名
			String fileName = "uecOutStaffAss_template.xls";
			// 编码后文件名
			String encodedName = null;
			encodedName = URLEncoder.encode(fileName, charset);
			// 将空格替换为+号
			encodedName = encodedName.replace("%20", "+");
			HttpServletRequest httpRequest = (HttpServletRequest) Executions
					.getCurrent().getNativeRequest();
			// 解决ie6 bug 或者是火狐浏览器
			if (encodedName.length() > 150 || Servlets.isGecko(httpRequest)
					|| Servlets.isGecko3(httpRequest)) {
				encodedName = new String(fileName.getBytes(charset),
						"ISO8859-1");
			}
			Filedownload.save(
					new FileInputStream(httpRequest
							.getRealPath("/pages_nmg/uec_outStaff/doc/"
									+ fileName)), "application/octet-stream",
					encodedName);
		} catch (Exception e) {
			ZkUtil.showError("下载员工考核信息导入模版失败", "系统提示");
		}
	}

	/**
	 * 文件上传 导入员工
	 * 
	 * @param event
	 * @throws Exception
	 */
	public void onUpload$uploadButton(final ForwardEvent forwardEvent)
			throws Exception {
		String tips = "";
		if (!ApprovalUtil.getActivityFlag()) {
			tips = "确认批量导入文件？导入后将直接保存到人员信息！";
		} else {
			tips = "确认批量导入文件？导入后将直接发起流程！";
		}
		Messagebox.show(tips, "输入确认", Messagebox.OK | Messagebox.CANCEL,
				Messagebox.QUESTION, new EventListener() {
					@Override
					public void onEvent(Event event) throws Exception {
						if (((Integer) event.getData()).intValue() == Messagebox.OK) {
							cn.ffcs.uom.common.util.PubUtil.clearListbox(bean
									.getUecAssListbox());

							media = ((UploadEvent) forwardEvent.getOrigin())
									.getMedia();
							if (null == media) {
								ZkUtil.showError("请选择要上传的文件!", "系统提示");
								return;
							}
							String fileName = media.getName();
							if (!fileName.endsWith(".xls")
									&& !fileName.endsWith(".xlsx")) {
								ZkUtil.showError(
										"导入的文件必须是以.xls或.xlsx结尾的EXCEL文件!",
										"系统提示");
								return;
							}
							String[][] objArray = FileUtil.readExcel(media, 1,
									1);
							if (objArray == null || objArray.length == 0) {
								ZkUtil.showError("导入文件没有数据！", "错误信息");
								return;
							}
							setDataToRows(objArray, fileName);
						} else {
							return;
						}
					}
				});

	}

	private void setDataToRows(String[][] data, String fileName) {
		uecAssList.clear();
		String[] row = null;
		boolean isUpload = true;
		for (int i = 0; i < data.length; i++) {
			row = data[i];
			if (row.length != TOTAL_COLUMN + 1) {
				ZkUtil.showError("导入文件数据不全！", "错误信息");
				return;
			}

			UecAss uecAss = UecAss.newInstance();
			UecOutStaffInfo outStaffInfo = UecOutStaffInfo.newInstance();
			for (int j = 0; j < TOTAL_COLUMN; j++) {
				switch (j) {
				// 人员编码
				case 0:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("人员编码为空！", "错误提示");
						isUpload = false;
						return;
					}
					outStaffInfo.setPsnCode(data[i][j]);
					outStaffInfo = uecOutStaffManager.findUecOutStaffInfo(outStaffInfo);
					if (null == outStaffInfo) {
						ZkUtil.showError("外包人员编码输入有误！", "错误提示");
						isUpload = false;
						return;
					}
					break;
				// 姓名
				case 1:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("人员姓名为空!", "错误提示");
						return;
					}
					if (!data[i][j].equals(outStaffInfo.getPsnName())) {
						ZkUtil.showError("人员姓名输入有误!", "错误提示");
						return;
					}
					UecTrial qryUecTrial = UecTrial.newInstance();
					qryUecTrial.setStaffId(outStaffInfo.getOutStaffId());
					qryUecTrial.setNmStaffType(BaseUnitConstants.NM_OUT_STAFF_TYPE);
					qryUecTrial = uecTrialManager.findUecTrial(qryUecTrial);
					if (null == qryUecTrial) {
						ZkUtil.showError("此人未入职,请先执行入职操作", "温馨提示");
						return;
					}
					uecAss.setStaffId(outStaffInfo.getOutStaffId());
					break;
				// 考核类型
				case 2:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("考核类型为空！", "错误提示");
						isUpload = false;
						return;
					}

					StringBuilder assTypeBuilder = new StringBuilder(
							" select * from uec_bd_defdoc t where t.pk_defdoclist = '1001A1100000000003RN' "
							+ " and t.name = ? ");
					List<Object> assTypeparams = new ArrayList<Object>();
					assTypeparams.add(data[i][j]);
					UecBdDefdoc uecBdDefdoc = DefaultDaoFactory.getDefaultDao()
							.jdbcFindObject(assTypeBuilder.toString(),
									assTypeparams, UecBdDefdoc.class);
					if (StrUtil.isNullOrEmpty(uecBdDefdoc)) {
						ZkUtil.showError("考核类型填写不正确!", "错误提示");
						return;
					}

					uecAss.setGlbdef1(uecBdDefdoc.getPkDefdoc());
					break;
				// 考核方案名称
				case 3:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("考核方案名称为空！", "错误提示");
						isUpload = false;
						return;
					}

					uecAss.setSchemename(data[i][j]);
					break;
				// 绩效等级
				case 4:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("绩效等级为空！", "错误提示");
						isUpload = false;
						return;
					}

					StringBuilder pkPerankBuilder = new StringBuilder(
							" select * from uec_bd_defdoc t where t.pk_defdoclist = '1001Z71000000000DCPT' "
							+ " and t.name = ? ");
					List<Object> pkPerankparams = new ArrayList<Object>();
					pkPerankparams.add(data[i][j]);
					uecBdDefdoc = DefaultDaoFactory.getDefaultDao()
							.jdbcFindObject(pkPerankBuilder.toString(),
									pkPerankparams, UecBdDefdoc.class);
					if (StrUtil.isNullOrEmpty(uecBdDefdoc)) {
						ZkUtil.showError("绩效等级填写不正确!", "错误提示");
						 return;
					}
					uecAss.setPkPerank(uecBdDefdoc.getPkDefdoc());
					break;

				// 考核系数
				case 5:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("考核系数为空！", "错误提示");
						isUpload = false;
						return;
					}

					try {
						double quotiety = Double.parseDouble(data[i][j]);
						uecAss.setSchemequotiety(quotiety);
					} catch (Exception e) {
						ZkUtil.showError("考核系数值不对，应该为数字！", "错误提示");
						isUpload = false;
						return;
					}
					break;
				// 考核成绩
				case 6:
					if (StrUtil.isNullOrEmpty(data[i][j])) {
						ZkUtil.showError("考核成绩为空！", "错误提示");
						isUpload = false;
						return;
					}

					try {
						double score = Double.parseDouble(data[i][j]);
						uecAss.setSchemescore(score);
					} catch (Exception e) {
						ZkUtil.showError("考核成绩数值不对，应该为数字！", "错误提示");
						isUpload = false;
						return;
					}
					break;
				// 起始日期
				case 7:
//					if (StrUtil.isNullOrEmpty(data[i][j])) {
//						ZkUtil.showError("起始日期为空！", "错误提示");
//						isUpload = false;
//						return;
//					}
					try {
						new SimpleDateFormat("yyyy-MM-dd").parse(data[i][j]);
					} catch (ParseException e) {
						e.printStackTrace();
						ZkUtil.showError("起始日期格式不正确！", "错误提示");
						isUpload = false;
						return;
					}
					uecAss.setGlbdef2(data[i][j]);
					break;
				// 组织考核成绩
				case 8:
//					if (StrUtil.isNullOrEmpty(data[i][j])) {
//						ZkUtil.showError("组织考核成绩为空！", "错误提示");
//						isUpload = false;
//						return;
//					}

					try {
						double score = Double.parseDouble(data[i][j]);
						uecAss.setGlbdef3(score);
					} catch (Exception e) {
						ZkUtil.showError("组织考核成绩数值不对，应该为数字！", "错误提示");
						isUpload = false;
						return;
					}
					break;
				// 期间名称
				case 9:
					uecAss.setGlbdef4(data[i][j]);
					break;
				// 考核期间类型
				case 10:
//					if (StrUtil.isNullOrEmpty(data[i][j])) {
//						ZkUtil.showError("考核期间类型为空！", "错误提示");
//						isUpload = false;
//						return;
//					}

					StringBuilder glbdef5Builder = new StringBuilder(
							" select * from uec_bd_defdoc t where t.pk_defdoclist = '1001A1100000000003RN' "
							+ " and t.name = ? ");
					List<Object> glbdef5Params = new ArrayList<Object>();
					glbdef5Params.add(data[i][j]);
					uecBdDefdoc = DefaultDaoFactory.getDefaultDao()
							.jdbcFindObject(glbdef5Builder.toString(),
									glbdef5Params, UecBdDefdoc.class);;
					if (StrUtil.isNullOrEmpty(uecBdDefdoc)) {
						ZkUtil.showError("考核期间类型填写不正确!", "错误提示");
						return;
					}
					uecAss.setGlbdef5(uecBdDefdoc.getPkDefdoc());
					break;
				default:
					break;
				}

			}
			if (!isUpload) {
				return;
			}

			if (StrUtil.isNullOrEmpty(PlatformUtil.getCurrentUser())) {
				ZkUtil.showError("当前用户不存在！", "错误提示");
				return;
			}

			uecAss.setCreator(PlatformUtil.getCurrentUser().getScreenName());
			uecAss.setCreationtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
					.format(new Date()));
			// 组织
			uecAss.setPkOrg(outStaffInfo.getPkHrorg());
			// 考核组织  ： 申请人所在组织
			uecAss.setPkOrgass(outStaffInfo.getPkHrorg());
			// 所属组织
			uecAss.setPkOrgpsn(outStaffInfo.getPkHrorg());
			uecAss.setDr(0L);
			uecAss.setLastflag("Y");

			uecAss.setNmStaffType(BaseUnitConstants.NM_OUT_STAFF_TYPE);

			uecAssList.add(uecAss);
		}

		if (null != uecAssList) {
			ListModel list = new BindingListModelList(uecAssList, true);
			this.bean.getUecAssListbox().setModel(list);
			this.bean.getUecAssListboxPaging().setTotalSize(1);

			if (ApprovalUtil.getActivityFlag()) {
				if (StrUtil.isNullOrEmpty(PlatformUtil.getCurrentUser())) {
					ZkUtil.showError("当前登录用户已失效，请重新登录!", "错误提示");
					return;
				}
				String currentName = PlatformUtil.getCurrentUser()
						.getScreenName();

				String formTheme = "盟市外包人员考核批量申请流程";
				String procInstId = null;
				for (UecAss uecAss : uecAssList) {

					// 发起流程 uec_punish 新增一条记录
					// 判断该人员是否在审状态，如果是在审状态不允许再次发起此流程
					// boolean isOnApproval =
					// ApprovalUtil.isOnApproval(procDefId,
					// uecOutStaffInfo.getOutStaffId());
					// if (isOnApproval) {
					// ZkUtil.showError("在审状态不允许发起！", "错误提示");
					// return;
					// }

					Long outStaffId = uecAss.getStaffId();
					UecOutStaffInfo outStaffInfo = UecOutStaffInfo.newInstance();
					outStaffInfo.setOutStaffId(outStaffId);
					outStaffInfo = uecOutStaffManager.findUecOutStaffInfoByOutStaffId(outStaffInfo);

					uecAss.addStatusCdIS3();
					Long assId = uecAss.getAssId();

					String startFlowJson = "{" + "formTheme: '" + formTheme
							+ "'," + " formContent: '考核人员:"
							+ outStaffInfo.getPsnName() + "',"
							+ " procDefId: '"
							+ ApprovalConstants.OUT_STAFF_ASSESS_PROC_DEF_ID
							+ "'," + " urgent: '1'," + " atiActCategoryId: '"
							+ ApprovalConstants.MODIFICATION_CATEGORY_ID + "',"
							+ " procDefKey: '"
							+ ApprovalUtil.OUT_STAFF_ASS_EDIT + "',"
							+ " formSender: '" + currentName + "',"
							+ " primaryId: '{" + "uec_out_staff_info_his:"
							+ outStaffId + ",uec_out_staff_info:" + outStaffId
							+ ",uec_ass:" + assId + "'}";

					try {
						procInstId = ApprovalUtil.startApproval(startFlowJson);
					} catch (Exception e) {
						// 流程发起失败 数据改为失效
						uecAss.removeOnly();
						onResetUecAss();
						ZkUtil.showError("流程发起失败！", "错误提示");
						e.printStackTrace();
					}
					if (StrUtil.isNullOrEmpty(procInstId)) {
						uecAss.removeOnly();
						onResetUecAss();
						ZkUtil.showError("流程发起失败！", "错误提示");
						return;
					}
					// 第一审批人如果是发起人直接到人力审批环节
					ApprovalUtil.isCurrentAssignNames(procInstId);

				}
				ApprovalUtil.showNextAssignee(procInstId, formTheme);
			} else {
				for (UecAss uecAss : uecAssList) {
					uecAss.addOnly();
				}
				ZkUtil.showInformation("批量导入考核信息已保存成功", "温馨提示");
			}

		}

	}

	/**
	 * 翻页
	 */
	public void onUecOutAssListboxPaging() {
		this.onQueryUecAssList();
	}

	/**
	 * 清除变量
	 */
	public void clearVariable() {
		uecAss = null;
	}

	/**
	 * 查询
	 */
	public void onQueryUecAssList() {
		if (null != assPaging) {
			PageInfo pageInfo = uecAssManager.queryPageInfoByUecAss(assPaging,
					this.bean.getUecAssListboxPaging().getActivePage() + 1,
					this.bean.getUecAssListboxPaging().getPageSize());
			ListModel list = new BindingListModelList(pageInfo.getDataList(),
					true);
			this.bean.getUecAssListbox().setModel(list);
			this.bean.getUecAssListboxPaging().setTotalSize(
					pageInfo.getTotalCount());

			uecAss = null;
		} else {
			cn.ffcs.uom.common.util.PubUtil.clearListbox(bean
					.getUecAssListbox());
		}
	}
}
